<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var nums = [1, 8, 6, 2, 5, 4, 8, 3, 7];
        function fn(nums) {
            // 双指针 收缩 
            var max = 0;
            for (var i = 0, j = nums.length-1; i < j;) {
                var minHeight = nums[i] < nums[j] ? nums[i++] : nums[j--];
                max = Math.max(max, (j - i + 1) * minHeight);
            }
            return max;
        }
        console.log(fn(nums));
    </script>
</body>

</html>